package jmine.tec.database.query.condition;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import jmine.tec.database.query.Column;
import jmine.tec.database.query.Condition;

/**
 * Condição de igualdade de uma coluna a um determinado valor.
 * 
 * @author lundberg
 */
public class EqualityCondition implements Condition {

    private final Column column;

    private final String value;

    /**
     * Construtor
     * 
     * @param column column
     * @param value value
     */
    public EqualityCondition(Column column, String value) {
        this.column = column;
        this.value = value;
    }

    /**
     * {@inheritDoc}
     */
    public String createQueryCondition() {
        return this.column.getName() + " = ?";
    }

    /**
     * {@inheritDoc}
     */
    public int setParameters(PreparedStatement st, int parameterIndex) throws SQLException {
        this.column.setParameter(st, parameterIndex, this.value);
        return parameterIndex + 1;
    }
}
